/**
 * @Author ZhangCuirong
 * @Date 2025/9/3 14:34
 * @description:
 */
public class Solution55 {
    public boolean canJump(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                boolean canJumped = false;
                for (int j = 0; j <= i; j++) {
                    if (i == nums.length - 1) {
                        if (nums[j] >= i - j) {
                            return true;
                        }
                    } else {
                        if (nums[j] > i - j) {
                            canJumped = true;
                        }
                    }
                }
                if (!canJumped) {
                    return false;
                }
            }
        }
        return true;
    }

    public boolean canJump2(int[] nums) {
        int farthest = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            farthest = Math.max(farthest, i + nums[i]);
            if (farthest <= i) {
                return false;
            }
        }
        return farthest >= nums.length - 1;
    }

    public static void main(String[] args) {
        Solution55 solution = new Solution55();
        System.out.println(solution.canJump(new int[]{2, 3, 1, 1, 4}));
        System.out.println(solution.canJump(new int[]{3, 2, 1, 0, 4}));
        System.out.println(solution.canJump(new int[]{0}));
        System.out.println(solution.canJump(new int[]{2, 0, 0}));
    }
}
